package gw.com.android.ui.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.gwtsz.gts2.hx.R;

import gw.com.android.app.ActivityManager;
import gw.com.android.app.AppMain;
import gw.com.android.app.GTConfig;
import gw.com.android.model.ConfigType;
import gw.com.android.model.ConfigUtil;
import www.com.library.model.DataItemDetail;
import www.com.library.util.AESCrypto2;
import www.com.library.util.DeviceUtil;

/**
 * Created by jay on 2017/7/11.
 */
public class AddAccountInfoDialog extends BaseDialog implements View.OnClickListener {

    private String uuid;
    private String mobilePhone;

    public AddAccountInfoDialog(Context context, String content, String uuid, String mobilePhone) {
        super(context);
        mContent = content;
        this.uuid = uuid;
        this.mobilePhone = mobilePhone;
    }

    private TextView mView;
    private String mContent = "";

    /**
     * 显示弹层
     *
     * @param act
     */
    public static void showAddAccountInfoDialog(Activity act, String content, String uuid, String mobilePhone) {
        mInstance = new AddAccountInfoDialog(act, content, uuid, mobilePhone);
        mInstance.show();
    }

    @Override
    public void initParam() {
        mCustomViewResId = R.layout.dialog_tourist_login_content;
        mBtnPosText = AppMain.getAppString(R.string.btn_add_info);
        mBtnNegText = AppMain.getAppString(R.string.btn_close);
        int padding = (int) (15 * DeviceUtil.instance().getScreenDensity(mOwnerAct));
        setPadding(padding, 0, padding, 0);
    }

    @Override
    public void inflaterCustomView(View mCustomView) {
        mView = (TextView) mCustomView.findViewById(R.id.dialog_content_text);
        mBtnPos.setOnClickListener(this);
        mBtnNeg.setOnClickListener(this);
        if (mContent.length() > 0) {
            mView.setText(mContent);
        }
    }

    // -------------------------------------------------------------
    // Functions of OnClickListener
    // -------------------------------------------------------------
    @Override
    public void onClick(View v) {
        v.setClickable(false);
        v.setEnabled(false);
        dismiss();
        switch (v.getId()) {
            // 补充资料
            case R.id.action_btn_pos:
                DataItemDetail item = new DataItemDetail();
                String url = ConfigUtil.instance().getUrlPath(ConfigType.RELATED_REAL_ACCOUNT);
                try {
                    url = url.replace(ConfigType.REPLACE_LOGIN_TAG, AESCrypto2.Encrypt(GTConfig.instance().mCurName));
                    url = url.replace(ConfigType.REPLACE_MOBILE_PHONE_TAG, AESCrypto2.Encrypt(mobilePhone));
                    url = url.replace(ConfigType.REPLACE_UUID_TAG, AESCrypto2.Encrypt(uuid));
                    url = url + "&utm_terminal=android";
                } catch (Exception e) {
                    e.printStackTrace();
                }
                item.setStringValue(ConfigType.CONFIG_TYPE_TYPE_URL_TAG, url);
                item.setStringValue(ConfigType.CONFIG_TYPE_TYPE_TAG, ConfigType.CONFIG_TYPE_TYPE_URL_TAG);
                item.setStringValue(ConfigType.CONFIG_TYPE_TITLE_TAG, AppMain.getAppString(R.string.btn_add_info));

                ActivityManager.showWebPageActivity(mOwnerAct, item, AppMain.getAppString(R.string.btn_back));
                break;
            // 取消
            case R.id.action_btn_neg:
                dismiss();
                break;
        }
    }
}
